﻿using System.Text;
using System.Web.UI.WebControls;
//using Microsoft.Office.Server.Search.Query;
//using SortDirection=Microsoft.Office.Server.Search.Query.SortDirection;

namespace zevenseas.Community.Search
{
    public class SortStatement
    {
        private string sortProperty;
        private SortDirection resultSortOrder = SortDirection.Descending;

        public SortDirection ResultSortOrder
        {
            get { return resultSortOrder; }
            set { resultSortOrder = value; }
        }

        public string SortProperty
        {
            get { return sortProperty; }
            set { sortProperty = value; }
        }

        public override string ToString()
        {
            StringBuilder sortStatement = new StringBuilder();
            sortStatement.Append(@" ORDER BY """);

            if (string.IsNullOrEmpty(sortProperty))
            {
                sortStatement.Append("Rank");
            }
            else
            {
                sortStatement.Append(sortProperty);
            }

            sortStatement.Append(@"""");

            if (resultSortOrder == SortDirection.Ascending)
            {
                sortStatement.Append(" ASC");
            }
            else
            {
                sortStatement.Append(" DESC");
            }

            return sortStatement.ToString();
        }
    }
}